/*
Rilego - An easy Images 2 PDF converter.
Copyright (C) 2011  Federico Improta (Kirys)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
/*
Rilego - An easy Images 2 PDF converter.
Copyright (C) 2011  Federico Improta (Kirys)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
#include <stdlib.h>
#include <windows.h>
#include <shlwapi.h>
BOOL GetModulePath(TCHAR* pBuf, DWORD dwBufSize) {

  if (GetModuleFileName(NULL,pBuf,dwBufSize)) {

    PathRemoveFileSpec(pBuf); // remove executable name

    return TRUE;
  }

  return FALSE;
}

int main( int argc, const char* argv[] ){
    char system[4096];
    GetSystemDirectory(system,4096);
    char java[4096];
    char parameters[4096];
    char exepath[MAX_PATH];
    GetModulePath(exepath, MAX_PATH);
    if (1){
        sprintf(java,"\"%s\\javaw.exe\"\0",system);
        sprintf(parameters,"-jar \"%s\\%s\"\0",exepath,"rilego.jar");
        HINSTANCE r = ShellExecute(GetDesktopWindow(),"open",java,parameters,NULL,SW_SHOWNORMAL);
        if (r>ERROR_SUCCESS){
            printf("%s %s %s %d\n",java,parameters,exepath,r);
        }else {
            int msgboxID = MessageBox(NULL,
        "Could not run Rilego, check if java is installed",
        "Rilego",
        MB_ICONERROR | MB_OK
    );
        }
#ifdef _DEBUGMODE_
        char appo[4096];

        sprintf(appo,"Java:%s\nparamaters:%s",java,parameters);
        MessageBox(NULL,
        appo,
        "Synedes",
        MB_ICONERROR | MB_OK
    );
#endif

    }
}
